package com.vip.base.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import javax.persistence.*;
import java.util.Date;

@MappedSuperclass
@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler"})
public class BaseEntity extends BaseDomain {

    /**
     * JPA提供的四种标准用法为TABLE，SEQUENCE，IDENTITY，AUTO。
     * a，TABLE：使用一个特定的数据库表格来保存主键。
     * b，SEQUENCE：根据底层数据库的序列来生成主键，条件是数据库支持序列。
     * c，IDENTITY：主键由数据库自动生成（主要是自动增长型）
     * d，AUTO：主键由程序控制。
     */



    @Column(name = "DATECREATED")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    protected Date dateCreated;

    @Column(name = "DATEMODIFIED")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    protected Date dateModified;

    @Column(name = "DELETED")
    protected Boolean deleted;




    @Version
    @Access(AccessType.FIELD)
    private long version;




    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    public Date getDateCreated() {
        return dateCreated;
    }

    public void setDateCreated(Date dateCreated) {
        this.dateCreated = dateCreated;
    }

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    public Date getDateModified() {
        return dateModified;
    }

    public void setDateModified(Date dateModified) {
        this.dateModified = dateModified;
    }

    public Boolean getDeleted() {
        return deleted;
    }

    public void setDeleted(Boolean deleted) {
        this.deleted = deleted;
    }





    public long getVersion() {
        return version;
    }

    public void setVersion(long version) {
        this.version = version;
    }





    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
    }
}
